class Solution:
    def minDays(self, bloomDay: list, m: int, k: int) -> int:
        if k * m > len(bloomDay):
            return -1
        left = min(bloomDay)
        right = max(bloomDay)
        while left < right:
            mid = (left + right) // 2
            bouquets = 0
            flowers = 0
            for day in bloomDay:
                if day <= mid:
                    flowers += 1
                else:
                    flowers = 0
                if flowers == k:
                    bouquets += 1
                    flowers = 0
            if bouquets >= m:
                right = mid
            else:
                left = mid + 1

        return right
